﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ETADTools.Lib
{
  public class FieldList: List<Field>
  {
    #region - Form methods -

    /// <summary>
    /// Convert the field to sql script based on styles.
    /// This one is suitable for most of purposes.
    /// </summary>
    /// <param name="separator"></param>
    /// <param name="styles"></param>
    /// <returns></returns>
    public string ToSqlScript(string separator, params Style[] styles)
    {
      #region .NET 2.0 and .NET 3.0
      //.NET 2.0
      //StringBuilder result = new StringBuilder();

      //for (int i = 0; i < this.Count - 1; ++i)
      //{
      //  result.AppendFormat(separator, this[i].ToSqlScript());
      //}
      //result.AppendFormat(this[this.Count - 1].ToSqlScript());

      //return result.ToString();

      //.NET 3.0/3.5
      //return string.Join(separator, this.Select(t => t.ToSqlScript()).ToArray());
      #endregion

      //.NET 4.0
      return string.Join(separator, this.Select(t => t.ToSqlScript(styles)));
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="tableAlias"></param>
    /// <returns></returns>
    public string ToSqlSelect(string tableAlias)
    {
      return string.Join(",\n\t\t", this.Select(t => t.ToSqlGetQuery(tableAlias)));
    }

    #endregion

  }
}
